﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Drawing;
using System.Drawing.Imaging;

namespace THO7AlgoritmTimerApplication
{
    class InvertAlgorithm : VisionAlgorithm
    {
        public InvertAlgorithm(String name) : base(name) { }
        public override System.Drawing.Bitmap DoAlgorithm(System.Drawing.Bitmap sourceImage)
        {
          Bitmap returnImage = new Bitmap(sourceImage);
            Graphics g = Graphics.FromImage(returnImage);
            ColorMatrix colorMatrix = new ColorMatrix(
                new float[][] 
                {
                    new float[] {-1, 0, 0, 0, 0},
                    new float[] {0, -1, 0, 0, 0},
                    new float[] {0, 0, -1, 0, 0},
                    new float[] {0, 0, 0, 1, 0},
                    new float[] {1, 1, 1, 0, 1}
                });
            ImageAttributes attributes = new ImageAttributes();
            attributes.SetColorMatrix(colorMatrix);
           
            g.DrawImage(sourceImage, new Rectangle(0, 0, sourceImage.Width, sourceImage.Height),
      0, 0, sourceImage.Width, sourceImage.Height, GraphicsUnit.Pixel, attributes);
            g.Dispose();
            return returnImage;
        }
    }
}

